import jwtDecode from "jwt-decode";
import api from "@/common/request/Api.js"
//获取小程序的场景值
export let getScene = () => {
	let obj = uni.getLaunchOptionsSync();
	return obj.scene
}
//清除场景值，临时用户标志和token
export let remolveTemporaryInfo = () => {
	uni.removeStorageSync("token"),
		uni.removeStorageSync("scene")
	uni.removeStorageSync("is_visitor")
}
// 拿其他场景的参数
export let getSceneQuery = () => {
	let obj = uni.getLaunchOptionsSync();
	return obj.query

}
// 得到用户信息或者token 不传默认返回用户信息
export let temporaryToken = async (type = 'userInfo') => {
	return new Promise(async (resolve, reject) => {
		let respon = await api.temporaryToken()
		if (respon.code === 20000) {
			let token = respon.data.token
			if (type === 'userInfo') {
				let userInfo = jwtDecode(token).data
				resolve(userInfo)
			} else {
				console.log("异步里面");
				resolve(token)
				
			}

		}
	})

}